package com.example.blockbreaker;

import android.app.Application;
import java.util.concurrent.Executor;
import androidx.lifecycle.LiveData;
import java.util.List;
public class CravingRepository {
    private final CravingDao cravingDao;
    private final Executor executor;

    public CravingRepository(Application application) {
        AppDatabase db = AppDatabase.getDatabase(application);
        cravingDao = db.cravingDao();
        executor = AppDatabase.getExecutor();
    }

    // =============== 增删改 ===============
    public void insertRecord(CravingRecord record) {
        executor.execute(() -> cravingDao.insert(record));
    }

    public void deleteRecord(CravingRecord record) {
        executor.execute(() -> cravingDao.delete(record));
    }

    // =============== 查询 ===============
    public LiveData<List<CravingRecord>> getAllRecords() {
        return cravingDao.getAllRecords();
    }

    public LiveData<List<CravingRecord>> getRecordsAfter(long timestamp) {
        return cravingDao.getRecordsAfter(timestamp);
    }

    public LiveData<Integer> getCountBetween(long start, long end) {
        return cravingDao.getCountBetween(start, end);
    }

    public LiveData<Float> getAverageLevelSince(long timestamp) {
        LiveData<Float> rv = null;
        LiveData<List<CravingRecord>> list=getRecordsAfter(timestamp);
        return rv;
    }
}